package com.itheima.tliasmanager.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.tliasmanager.exception.DeptNotAllowedDeleteException;
import com.itheima.tliasmanager.mapper.DeptMapper;
import com.itheima.tliasmanager.mapper.EmpMapper;
import com.itheima.tliasmanager.pojo.domain.Dept;
import com.itheima.tliasmanager.pojo.domain.Emp;
import com.itheima.tliasmanager.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public void removeByDeptId(Integer id) {
        List<Emp> emps = empMapper.listByDeptId(id);
        if (emps != null && !emps.isEmpty()) {
            throw new DeptNotAllowedDeleteException("该部门有员工，不允许删除");
        }

        removeById(id);
    }

    @Override
    public void saveDept(Dept dept) {
        save(dept);
    }

    @Override
    public void updateByDeptId(Dept dept) {
        updateById(dept);
    }


}
